<?php
 include_once 'class.php'; if ($_POST['password']!=""&&$_POST['password']==$yanzhengma){ }else{ if($_POST['password']!=""||$_POST['password']==""){ echo "<script> alert('安全码错误！');parent.location.href='index.php'; </script>"; exit; } } ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>诚信娱乐</title>
<link rel="stylesheet" href="css/css.css" />
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div class="top"><a href="#"><div class="csBtn"  onclick="test(0)">測速</div></a><?php echo $name; ?></div>
<div class="mainBox">

	<!--会员-->
	<div class="title">诚信娱乐會員線路系統</div>
	<div class="listBox">
	<ul>
        
         <?php
 echo $huiyuan; ?>

	</ul>
	<div class="clear"></div>
	</div>
	
	<!--代理-->
	<div class="title1">诚信娱乐代理線路系統</div>
	<div class="listBox1">
	<ul>
		
				<?php
 echo $daili; ?>
				
                
	</ul>
	<div class="clear"></div>
	</div><br />
<div class="clear"></div>
</div>
<br />

  <div class="clear"></div>
</div>
<script>

    var li = document.getElementsByTagName("li");
    var st; 
    var count = 0;
    var oSpeed = document.getElementById('speed');

    var cache = [],
    timeout = null;

    var cacheImg = function () {
        var cid = '';
        for (var c = 0; c < li.length; c++) {
            var clink = {}
            cid = c + '';
            clink.img = document.createElement('img');
            clink.url = li[c].getElementsByTagName("a")[0].href.split('/').slice(0, 3).join('/') + "/speed.png?";
            clink.time = 0;
            clink.number = 0;
            clink.img.onerror = getError;
            clink.img.onload = getLoad;
            clink.img.id = cid;
            clink.loadTime = [];
            clink.stop = false;
            cache[c] = clink;
        }
    }
    var clear = function (c) {
        clearTimeout(timeout);
        timeout = null;
        if (!c) {
            for (var i = li.length - 1; i >= 0; i--) {
                if (li[i].getElementsByTagName('b').length) {
                    li[i].getElementsByTagName('b')[0].innerHTML = '';
                }
            };
        };
    }
    var test = function (c) {
        clear(c);

        var cid = "";
        if (cache.length > 0 && cache[c]) {
            if (li[c].getElementsByTagName("b").length > 0) {
                li[c].getElementsByTagName("b")[0].innerHTML = "測速中";
                cache[c].img.src = cache[c].url + (Math.random() + '').replace('0.', '');
            } else {
                var span = document.createElement("b");
                span.id = c + "m";
                span.innerHTML = "測速中";
                li[c].appendChild(span);
                cache[c].img.src = cache[c].url + (Math.random() + '').replace('0.', '');
                // console.log(oSpeed)
                speed.appendChild(cache[c].img);
            }
            cache[c].time = new Date().getTime();
            cache[c].stop = false;
            timeout = setTimeout(function () {
                getError.call(cache[c].img, c);
            }, 5000);
        } else {
            //btn.removeAttribute('disabled');
        };
    }

    function getError(c) {
        var n = this.id;
        if (typeof c === 'number') {
            n = c;
        };
        n = parseInt(n, 10);
        if (document.getElementById(this.id + 'm')) {
            if (!cache[parseInt(n, 10)].stop) {
                cache[parseInt(n, 10)].number = 0;
                cache[parseInt(n, 10)].stop = true;
                if (document.getElementById(n + 'm').innerHTML != '超時' || document.getElementById(n + 'm').innerHTML == '測速中') {
                    document.getElementById(n + 'm').innerHTML = '极速...';
                }
            };
            setTimeout(function () {
                test(n + 1);
            }, 500);
        }
    }

    function getLoad() {

        var end = new Date().getTime(),
            cid = parseInt(this.id, 10),
            clink = cache[cid],
            td = clink.number ? end - cache[cid].time : end - cache[cid].time,
            total = 0;
        cache[cid].loadTime.push(td);
        cache[cid].number += 1;
        if (cache[cid].stop) {
            return;
        }

        if (cache[cid].number < 2) {

            setTimeout(function () {
                test(cid);
            }, 500);

        } else {
            for (var c = 0; c < 2; c++) {
                total += clink.loadTime[c];
            }
            document.getElementById(cid + 'm').innerHTML = (total / 2).toFixed(2)+'毫秒';
            count -= 1;
            cache[cid].number = 0;
            cache[cid].loadTime.length = 0;
            cache[cid].stop = true;
            setTimeout(function () {
                test(cid + 1);
            }, 500);
        }
    }

    cacheImg();


</script>
</body>
</html>